package cn.edu.gdut.csq.controller;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.edu.gdut.csq.entity.ResultSet;
import cn.edu.gdut.csq.util.JsonUtils;

@Controller
public class PageController {

	@RequestMapping("/index")
	public String index() {

		System.out.println("index");
		return "index";
	}

	@RequestMapping("/center")
	@ResponseBody
	public String center(String current_page, HttpServletResponse res) {

		System.out.println("current_page " + current_page);

		if (current_page == null) {
			return JsonUtils.objectToJson(ResultSet
					.error("page parameter is miss!!"));
		}

		try {
			int page = Integer.parseInt(current_page);
			if (page < 0) {
				return JsonUtils.objectToJson(ResultSet
						.error("page parameter is error!!"));
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();

		}
		return JsonUtils.objectToJson(ResultSet
				.error("page parameter is right!!"));
	}

	@RequestMapping("/login")
	public String hello() {
		return "user/login";
	}

}
